public class DepthOfBinaryTree {
    // 求二叉树的最大、最小深度
    public static class TreeNode {
        public int val;
        public TreeNode left;
        public TreeNode right;
    }

    // 测试链接 : https://leetcode.cn/problems/maximum-depth-of-binary-tree/
    public int maxDepth(TreeNode root) {
        return root == null ? 0 : Math.max(maxDepth(root.left),  maxDepth(root.right)) + 1;
    }

    // 测试链接 : https://leetcode.cn/problems/minimum-depth-of-binary-tree/
    public int minDepth(TreeNode root) {
        if(root == null) {
            return 0;
        }
        if(root.left == null && root.right == null) {
            return 1;
        }

        int leftNum = Integer.MAX_VALUE;
        int rightNum = Integer.MAX_VALUE;
        if(root.left != null) {
            leftNum = minDepth(root.left) + 1;
        }
        if(root.right != null) {
            rightNum = minDepth(root.right) + 1;
        }
        int ans = Math.min(leftNum,rightNum);

        return ans;
    }
}
